<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    img {
      width: 100px;height: 100px;
    }
  </style>
</head>
<body>
  <input type="file">
  <script>
    var input = document.querySelector('input')

    var f = new FileReader()

    f.onload = function () {
      // console.log(this.result)
      // 生成img
      var img = new Image()
      img.src = this.result
      document.body.appendChild(img)
    }


    input.onchange = function () {
      // 得到file对象
      var file = this.files[0]
      // 用fileReader读file对象
      f.readAsDataURL(file)
      
    }
  </script>
  
</body>
</html>